<?php
declare (strict_types = 1);

namespace app\admin\controller;

use app\BaseController;
use app\model\Payment as PaymentModel;
class Payment extends BaseController
{
    public function index($limit=10)
    {
        $name = request()->param('name');
        $status = request()->param('status');
        $time = request()->param('time');
        $data= PaymentModel::where('type',1)->when($name, function ($query) use ($name) {
            $query->where('name', 'like', "%$name%");
        })->when($status, function ($query) use ($status) {
            $query->where('status', $status);
        })->when($time, function ($query) use ($time) {
            $query->whereBetween('create_time', $time);
        })->paginate($limit);
        return $this->success($data);
    }

    public function create()
    {
        $params=request()->param();
        $params['type']=1;
        PaymentModel::create($params);
        return $this->success();
    }

    public function update($id)
    {
        PaymentModel::where('id',$id)->update(request()->param());
        return $this->success();
    }

    public function delete($id)
    {
        PaymentModel::where('id','in',$id)->delete();
        return $this->success();
    }
}
